package cn.bjxy.shishaolong.system.controller;


import cn.bjxy.shishaolong.common.ResultMsg;
import cn.bjxy.shishaolong.common.StatusCode;
import cn.bjxy.shishaolong.system.annotation.Permission;
import cn.bjxy.shishaolong.system.entity.Resources;
import cn.bjxy.shishaolong.system.service.IResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 时少龙
 * @since 2019-03-31
 */
@RestController
@CrossOrigin
@RequestMapping("/api/admin/rs/resource")
public class ResourcesController {

    @Autowired
    private IResourcesService resourcesService;

    /**
     * 查询所有资源及当前角色已有资源权限
     *
     * @param
     * @return
     */
    @GetMapping("/getAllResourceAndChecked/{roleId}")
    @Permission
    public ResultMsg getAllResourceAndChecked(@PathVariable Integer roleId) {
        List<Resources> resourcesList = null;
        try {
            resourcesList = resourcesService.queryAllAndChecked(roleId);
        } catch (Exception e) {
            return ResultMsg.create(StatusCode.QUERY_FAILURE, StatusCode.QUERY_FAILURE_MSG);
        }
        return ResultMsg.success(resourcesList);
    }
}
